<?php
/**
 * 애드페이 (AD-Pay for Gnuboard4)
 *
 * Copyright (c) 2010 Choi Jae-Young <www.miwit.com>
 *
 * 저작권 안내
 * - 저작권자는 이 프로그램을 사용하므로서 발생하는 모든 문제에 대하여 책임을 지지 않습니다. 
 * - 이 프로그램을 어떠한 형태로든 재배포 및 공개하는 것을 허락하지 않습니다.
 * - 이 저작권 표시사항을 저작권자를 제외한 그 누구도 수정할 수 없습니다.
 */

include_once("_common.php");
include_once("_config.php");
include_once("_lib.php");

$pr = array();

if ($or_id && $w == "u")
{
    $order = sql_fetch("select * from $pb[order_table] where or_id = '$or_id'");
    if (!$order)
        alert("주문서가 없습니다.");

    $mb = get_member($order[mb_id], "mb_id, mb_nick, mb_email, mb_homepage");
    $mb_name = get_sideview($mb[mb_id], $mb[mb_nick], $mb[mb_email], $mb[mb_homepage]);

    $product = sql_fetch("select * from $pb[product_table] where pr_id = '$order[pr_id]'");
}
//else alert("주문번호가 없습니다.");
else
{
    if ($pr_code)
        $product = sql_fetch("select * from $pb[product_table] where pr_code = '$pr_code'");

    $order[or_sdate] = $g4[time_ymd];
}

if (!$order[or_target])
    $order[or_target] = "_blank";

if (!$order['or_type'])
    $order['or_type'] = 'i';

$g4[title] = "애드페이 주문관리";
include_once("adm-head.php");
?>

<script src="<?=$g4[path]?>/js/sideview.js"></script>
<script src="<?=$g4[path]?>/js/board.js"></script>
<?
//==============================================================================
// jquery date picker
//------------------------------------------------------------------------------
// 참고) ie 에서는 년, 월 select box 를 두번씩 클릭해야 하는 오류가 있습니다.
//------------------------------------------------------------------------------
// jquery-ui.css 의 테마를 변경해서 사용할 수 있습니다.
// base, black-tie, blitzer, cupertino, dark-hive, dot-luv, eggplant, excite-bike, flick, hot-sneaks, humanity, le-frog, mint-choc, overcast, pepper-grinder, redmond, smoothness, south-street, start, sunny, swanky-purse, trontastic, ui-darkness, ui-lightness, vader
// 아래 css 는 date picker 의 화면을 맞추는 코드입니다.
?>

<link type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.4/themes/base/jquery-ui.css" rel="stylesheet" />
<style type="text/css">
<!--
.ui-datepicker { font:12px dotum; }
.ui-datepicker select.ui-datepicker-month, 
.ui-datepicker select.ui-datepicker-year { width: 70px;}
.ui-datepicker-trigger { margin:0 0 -5px 2px; }
-->
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.4/jquery-ui.min.js"></script>
<script>
/* Korean initialisation for the jQuery calendar extension. */
/* Written by DaeKwon Kang (ncrash.dk@gmail.com). */
jQuery(function($){
    $.datepicker.regional['ko'] = {
            closeText: '닫기',
            prevText: '이전달',
            nextText: '다음달',
            currentText: '오늘',
            monthNames: ['1월(JAN)','2월(FEB)','3월(MAR)','4월(APR)','5월(MAY)','6월(JUN)',
            '7월(JUL)','8월(AUG)','9월(SEP)','10월(OCT)','11월(NOV)','12월(DEC)'],
            monthNamesShort: ['1월','2월','3월','4월','5월','6월',
            '7월','8월','9월','10월','11월','12월'],
            dayNames: ['일','월','화','수','목','금','토'],
            dayNamesShort: ['일','월','화','수','목','금','토'],
            dayNamesMin: ['일','월','화','수','목','금','토'],
            weekHeader: 'Wk',
            dateFormat: 'yy-mm-dd',
            firstDay: 0,
            isRTL: false,
            showMonthAfterYear: true,
            yearSuffix: ''};
    $.datepicker.setDefaults($.datepicker.regional['ko']);

    $('#or_sdate').datepicker({
        showOn: 'button',
        buttonImage: '<?=$g4[path]?>/img/calendar.gif',
        buttonImageOnly: true,
        buttonText: "달력",
        changeMonth: true,
        changeYear: true,
        showButtonPanel: true,
        yearRange: 'c-99:c+99'
    }); 
    $('#or_edate').datepicker({
        showOn: 'button',
        buttonImage: '<?=$g4[path]?>/img/calendar.gif',
        buttonImageOnly: true,
        buttonText: "달력",
        changeMonth: true,
        changeYear: true,
        showButtonPanel: true,
        yearRange: 'c-99:c+99'
    }); 
});
</script>
<?
//==============================================================================
?>

<link rel="stylesheet" href="style.css" type="text/css"/>
<style type="text/css">
.tdh { width:120px; }
.tdb { text-align:left; padding:0 0 0 10px; }
.tdb .tip { font-size:11px; color:#888; }
</style>

<h3> <img src="img/miwit.gif" align="absmiddle"> <?=$g4[title]?> </h3>
<form name="fconfig" method="post" action="adm-order-update.php" enctype="multipart/form-data">
<input type="hidden" name="w" value="<?=$w?>"/>
<input type="hidden" name="or_id" value="<?=$order[or_id]?>"/>
<input type="hidden" name="page" value="<?=$page?>"/>
<input type="hidden" name="pr_code" value="<?=$pr_code?>"/>
<input type="hidden" name="sfl" value="<?=$sfl?>"/>
<input type="hidden" name="stx" value="<?=$stx?>"/>
<input type="hidden" name="status" value="<?=$status?>"/>

<table class="content" width="100%" border="1" cellspacing="0" cellpadding="0" bordercolor="#cccccc">
<? if ($w == 'u') { ?>
<tr>
    <td class="tdh"> <div>주문번호</div> </td>
    <td class="tdb">
        <?=$order[or_id]?>
    </td>
</tr>
<? } ?>
<tr>
    <td class="tdh"> <div>배너코드</div> </td>
    <td class="tdb">
        <? 
        if ($w == 'u') echo "$product[pr_code] ($product[pr_name])";
        else {
        ?>
        <select name="pr_id" required itemname="배너코드">
        <option value=""></option>
        <?
        $qry = sql_query("select * from $pb[product_table] order by pr_id");
        for ($i=0; $row=sql_fetch_array($qry); $i++) {
        ?>
        <option value="<?=$row[pr_id]?>"><?=$row[pr_name]?> </option>
        <? } ?>
        </select>
        <script> fconfig.pr_id.value = "<?=$product[pr_id]?>"; </script>
        <? } ?>
        <span class="tip"><? if ($w=="u") echo "&nbsp;&nbsp;&nbsp; 사용방법 : ".htmlspecialchars('<?=mw_pay_banner("'.$product[pr_code].'", "basic")?>'); ?> </span>
    </td>
</tr>
<tr>
    <td class="tdh"> <div>회원ID</div> </td>
    <td class="tdb">
        <? if ($w == 'u') echo $mb_name;
        else {?>
        <input type="text" size="10" name="mb_id" required itemname="회원ID" value="<?=$member[mb_id]?>">
        <? } ?>
    </td>
</tr>
<tr>
    <td class="tdh"> <div>승인</div> </td>
    <td class="tdb">
        <input type="checkbox" name="or_app" value="1">
        승인합니다.
        <script>
        document.fconfig.or_app.checked = "<?=$order[or_app]?>";
        </script>
    </td>
</tr>
<tr>
    <td class="tdh"> <div>시작일</div> </td>
    <td class="tdb">
        <input type="text" size="12" maxlength="10" name="or_sdate" id="or_sdate" value="<?=$order[or_sdate]?>" required itemname="시작일" readonly>
    </td>
</tr>
<tr>
    <td class="tdh"> <div>종료일</div> </td>
    <td class="tdb">
        <input type="text" size="12" maxlength="10" name="or_edate" id="or_edate" value="<?=$order[or_edate]?>" required itemname="시작일" readonly>
    </td>
</tr>
<tr>
    <td class="tdh"> <div>광고종류</div> </td>
    <td class="tdb">
        <select name="or_type" required itemname="광고종류">
        <option value=""> </option>
        <option value="i"> 이미지 </option>
        <option value="c"> 광고코드 (애드센스등) </option>
        <script> fconfig.or_type.value = "<?=$order['or_type']?>"; </script>
    </td>
</tr>
<tr>
    <td class="tdh"> <div>사이트 이름</div> </td>
    <td class="tdb">
        <input type="text" name="or_site" size="50" required itemname="사이트 이름" value="<?=$order[or_site]?>" class="ed">
    </td>
</tr>
<tr>
    <td class="tdh"> <div>사이트 설명</div> </td>
    <td class="tdb">
        <input type="text" name="or_info" size="50" itemname="사이트 설명" value="<?=$order[or_info]?>" class="ed">
    </td>
</tr>
<tr>
    <td class="tdh"> <div>사이트 주소</div> </td>
    <td class="tdb">
        <input type="text" name="or_url" size="50" itemname="사이트 주소" value="<?=set_http($order[or_url])?>" class="ed">
    </td>
</tr>
<tr>
    <td class="tdh"> <div><?=$mw_cash[cf_cash_name]?></div> </td>
    <td class="tdb">
        <input type="text" name="or_cash" size="10" itemname="<?=$mw_cash[cf_cash_name]?>" value="<?=$order[or_cash]?>" class="ed">  <?=$mw_cash[cf_cash_unit]?>
    </td>
</tr>
<tr>
    <td class="tdh"> <div>포인트</div> </td>
    <td class="tdb">
        <input type="text" name="or_point" size="10" itemname="포인트" value="<?=$order[or_point]?>" class="ed"> 점
    </td>
</tr>
<tr>
    <td class="tdh"> <div>적립 포인트</div> </td>
    <td class="tdb">
        <input type="text" name="or_member_point" size="10" itemname="포인트" value="<?=$order[or_member_point]?>" class="ed"> 점
        <span class="tip"> (클릭한 회원에게 적립하는 포인트,
            0일 경우 배너상품 기본 포인트 <?=number_format($product[pr_member_point])?>점 적립,
            적립을 원치 않는 경우 -1 입력) </span>
    </td>
</tr>
<? if ($w == 'u') { ?>
<tr>
    <td class="tdh"> <div>통계</div> </td>
    <td class="tdb">
        <?=number_format($order[or_click])?>/<?=number_format($order[or_hit])?>
        <a style="text-decoration:underline; cursor:pointer;" onclick="open_stats(<?=$order[or_id]?>)">[자세히 보기]</a>
    </td>
</tr>
<tr>
    <td class="tdh"> <div>등록일시</div> </td>
    <td class="tdb">
        <?=$order[or_datetime]?>
    </td>
</tr>
<? } ?>
<tr>
    <td class="tdh"> <div>배너</div> </td>
    <td class="tdb" style="padding:10px;">
        <input type="file" name="or_file" size="40" itemname="배너" class="ed">
    </td>
</tr>
<tr>
    <td class="tdh"> <div>타겟</div> </td>
    <td class="tdb">
        <select name="or_target" required itemname="기본타겟">
        <option value=""> </option>
        <option value="_blank"> 새창 </option>
        <option value="_self"> 현재 </option>
        <option value="_top"> 전체 </option>
        <script> fconfig.or_target.value = "<?=$order[or_target]?>"; </script>
    </td>
</tr>
<tr>
    <td class="tdh"> <div>광고코드</div> </td>
    <td class="tdb">
        <textarea name="or_code" id="or_code" rows="5" cols="50" itemname="광고코드"><?=$order['or_code']?></textarea>
        <div class="tip"> 애드센스 등의 광고코드 입력용 </div>
    </td>
</tr>
</table>

<? if ($w == 'u') { ?>
<script src="<?=$g4[path]?>/js/board.js"></script>
<div style="margin:10px 0 10px 0;">
<div style="font-weight:bold;">등록된배너</div>
<div style="border:1px solid #ccc; padding:10px;">
    <?php
    if ($order['or_type'] == 'i') {
        echo mw_pay_banner_view($order[or_file], "", $product[pr_width], $product[pr_height],
         " name='target_resize_image[]' onclick='image_window(this);'");
    }
    else {
        echo $order['or_code'];
    }
    ?>
    </div>
</div>
<? } ?>

<script>
$(document).ready (function() {
    resizeBoardImage(700);
});
function open_stats(or_id) {
    win_stats = window.open('stats.php?or_id='+or_id, 'stats', 'width=800, height=600, scrollbars=yes');
    win_stats.focus();
}
</script>



<p align="center" style="margin-top:30px;">
    <input type="submit" value="확     인" class="btn1">
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <input type="button" value="목     록" class="btn1" onclick="location.href='adm-order.php?pr_code=<?=$pr_code?>&status=<?=$status?><?=$qstr?>'">
</p>

</form>

<?
include_once("adm-tail.php");
